package edu.gdkm.dao;

import edu.gdkm.pojo.Employee;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface EmployeeDAO {
    @Select("select * from employee where id = #{id}")
    Employee findById(Integer id);
    @Select("select * from employee where name = #{name}")
    Employee findByName(String name);
    @Select("select * from employee")
    List<Employee> findAll();
    @Insert("insert into employee(name, age, department_name, position_name, salary, hire_date, status, created_time) values(#{name}, #{age}, #{department_name}, #{position_name}, #{salary}, #{hire_date}, #{status}, #{created_time})")

    boolean save(Employee employee);
    @Update( "update employee set name = #{name}, age = #{age}, department_name = #{department_name}, position_name = #{position_name}, salary = #{salary}, hire_date = #{hire_date}, status = #{status}, updated_time = #{updated_time} where id = #{id}")
    boolean update(Employee employee);
    @Delete("delete from employee where id = #{id}")
    boolean delete(Integer id);
    @Select( "select sum(salary) from employee where department_name = #{department_name}")
    Double getSalarySumByDepartmentName(Employee employee);
    @Select("<script>select * from employee" +
                "<if test='department_name!=null and department_name!=\"\"'>" +
                    " where department_name = #{department_name}" +
                "</if>" +
            "</script>")
    List<Employee> findByDepartmentName(String department_name);
    @Delete("<script>" +
            "delete from employee where id in " +
                "<foreach collection='array' open='(' close=')' separator=',' item='id'>" +
                    "#{id}"+
                "</foreach>" +
            "</script>")
    boolean deleteByIds(Integer ids[]);

}
